﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BTGISWASECO.DataLayer;
using BTGISWASECO.BusinessEntities;
using BTGISWASECO.BusinessLayer;

public partial class PresentationLayer_DefaultTab : System.Web.UI.Page
{
    BeChuaBLL bll = new BeChuaBLL();
    DMHuongDongChayDAL DMHuongDongChayDal = new DMHuongDongChayDAL();
    BeChuaEntities BeChuaEntities = new BeChuaEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["DataTable"]=="")
                Response.Redirect("../default.aspx");

            for (int i = DateTime.Now.Year; i >= 1990; --i)
            {
                ListItem iteml = new ListItem(i.ToString(), i.ToString());
                DListNamXayDung.Items.Add(iteml);
            }
            BeChuaEntities = bll.GetBeChuaEntitiesByID();
            txtObjectID.Value = BeChuaEntities.OBJECTID.ToString();
            txtIDMaBeChua.Text = BeChuaEntities.IDMaBeChua;
            this.txtDMA.Text = BeChuaEntities.IDCapNuoc;
            this.txtTenBeChua.Text = BeChuaEntities.TenBeChua;
            this.txtDiaDiem.Text = BeChuaEntities.DiaDiem.ToString();
            foreach (var itemvl in DMVatLieuDAL.GetList())
            {
                if (BeChuaEntities.VatLieuText.ToString().Trim() == itemvl.MoTa.ToString().Trim())
                    BeChuaEntities.VatLieu = itemvl.Ma;
                ListItem iteml = new ListItem(itemvl.MoTa.ToString(), itemvl.Ma.ToString());
                DListVatLieu.Items.Add(iteml);
            }
            DListVatLieu.SelectedValue = BeChuaEntities.VatLieu.ToString();
            DListNamXayDung.SelectedValue = BeChuaEntities.NamXayDung.ToString();

            this.dDTKhuDat.Text = BeChuaEntities.DTKhuDat.ToString();
            this.dDTHuuDung.Text = BeChuaEntities.DTHuuDung.ToString();
            this.dCDOngXaDay.Text = BeChuaEntities.CDOngXaDay.ToString();
            this.dCDOngXaTran.Text = BeChuaEntities.CDOngXaTran.ToString();
            this.dKTNgoVao.Text = BeChuaEntities.KTNgoVao.ToString();
            this.dKTNgoRa.Text = BeChuaEntities.KTNgoRa.ToString();
            this.dDKOngXaTran.Text = BeChuaEntities.DKOngXaTran.ToString();
            this.dDKOngXaDay.Text = BeChuaEntities.DKOngXaDay.ToString();

            foreach (var itemnttsd in DMTinhTrangSDDAL.GetList())
            {
                if (BeChuaEntities.TinhTrangText.ToString().Trim() == itemnttsd.MoTa.ToString().Trim())
                    BeChuaEntities.TinhTrang = itemnttsd.Ma;
                ListItem iteml = new ListItem(itemnttsd.MoTa.ToString(), itemnttsd.Ma.ToString());
                DListTTSD.Items.Add(iteml);
            }
            DListTTSD.SelectedValue = BeChuaEntities.TinhTrang.ToString();

            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (BeChuaEntities.DonViQuanLyText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                    BeChuaEntities.DonViQuanLy = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViQL.Items.Add(iteml);
            }
            DListDonViQL.SelectedValue = BeChuaEntities.DonViQuanLy.ToString();

            this.txtKichThuocBe.Text = BeChuaEntities.KichThuocBe.ToString();

            this.txtSoNha.Text = BeChuaEntities.SoNha.ToString();
            this.txtMaDuong.Text = BeChuaEntities.MaDuong.ToString();
            this.txtMaPhuong.Text = BeChuaEntities.MaPhuong.ToString();
            this.txtMaQuan.Text = BeChuaEntities.MaQuan;
            this.txtGhiChu.Text = BeChuaEntities.GhiChu;

            this.txtMaTramBom.Text = BeChuaEntities.MaTramBom;


        }//ThuocSoHuu
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        BeChuaEntities bk = new BeChuaEntities();
        BeChuaDAL BeChuaDAL = new BeChuaDAL();
        //BeChuaEntities BeChuaEntities = new BeChuaEntities(Convert.ToInt32(DListDonViTC.SelectedValue = DListDonViTC.SelectedValue!=""?DListDonViTC.SelectedValue:"0"),
        //    Convert.ToInt32(DListDonViGS.SelectedValue = DListDonViGS.SelectedValue!=""?DListDonViGS.SelectedValue:"0"), this.txtNguoiCNC.Text, DateTime.Parse(this.txtNgayCNC.Text.ToString()), this.txtGhiChu.Text, this.txtMaHinhAnh.Text);
        BeChuaEntities BeChuaEntities = new BeChuaEntities(Convert.ToInt32(txtObjectID.Value), txtIDMaBeChua.Text, this.txtDMA.Text, this.txtTenBeChua.Text,
            this.txtDiaDiem.Text, Convert.ToInt32(DListVatLieu.SelectedValue = DListVatLieu.SelectedValue != "" ? DListVatLieu.SelectedValue : "0"),
            Convert.ToInt32(DListNamXayDung.SelectedValue), Convert.ToDouble(this.dDTKhuDat.Text),Convert.ToDouble(this.dDTHuuDung.Text),
            Convert.ToDouble(this.dCDOngXaDay.Text),Convert.ToDouble(this.dCDOngXaTran.Text),Convert.ToDouble(this.dKTNgoVao.Text),
            Convert.ToDouble(this.dKTNgoRa.Text),Convert.ToDouble(this.dDKOngXaTran.Text),Convert.ToDouble(this.dDKOngXaDay.Text),
            Convert.ToInt32(DListTTSD.SelectedValue = DListTTSD.SelectedValue != "" ? DListTTSD.SelectedValue : "0"),
            Convert.ToInt32(DListDonViQL.SelectedValue = DListDonViQL.SelectedValue != "" ? DListDonViQL.SelectedValue : "0"),
            this.txtKichThuocBe.Text,this.txtSoNha.Text,this.txtMaDuong.Text,this.txtMaPhuong.Text,
            this.txtMaQuan.Text,this.txtGhiChu.Text, this.txtMaTramBom.Text);
        BeChuaDAL.Update1(BeChuaEntities);
        //BeChuaDAL.Update(Convert.ToInt32(txtObjectID.Value), txtMaDoanOng.Text, txtDMA.Text, Convert.ToInt32(DListHDChay.SelectedValue), Convert.ToDouble(this.nChieuDai.Text));
       // Response.Redirect("../default.aspx");
        ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script language='JavaScript'>alert('Cập nhật thành công'); window.location.href ='../Default.aspx';</script>");
    }
    protected void btnHuyBo_Click(object sender, EventArgs e)
    {
        Response.Redirect("../default.aspx");
    }
}